package UDP;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.util.HashMap;
import java.util.Map;

//编写⼀个英译汉的服务器.只需要重写process⽅法即可.
//该服务器DicrServer继承自EchoServer.
public class DictServer extends EchoServer{
    private Map<String, String> dict = new HashMap<>();

    public DictServer(int port) throws Exception {
        super(port);
        dict.put("cat", "小猫");
        dict.put("dog", "小狗");
        dict.put("pig", "小猪");
        dict.put("bird", "小鸟");
        dict.put("sheep", "小羊");
        dict.put("cow", "小牛");
        dict.put("chicken", "小鸡");
        dict.put("rabbit", "小兔子");
        dict.put("fish", "小鱼");
        dict.put("wolf", "狼");
        dict.put("monkey", "猴子");
        dict.put("chicken", "小鸡");
        dict.put("fish", "小鱼");
        dict.put("tiger", "老虎");
        dict.put("lion", "狮子");
        dict.put("wolf", "狼");
        dict.put("monkey", "猴子");
    }

    @Override
    public String process(String request) {
        return dict.getOrDefault(request, "未找到该单词");
    }

    public static void main(String[] args) throws Exception {
        DictServer server = new DictServer(9090);
        server.start();
    }
}
